home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / dim-1.000 / dim-1 / dim-1.03 / src / fgetline.c < prev    next >
C/C++ Source or Header  |  1993-12-19  |  803b  |  37 lines

  1. #include "dim.h"
  2.  
  3. char *fgetline (FILE *inf)
  4. {
  5.     static char
  6.         buf [1000];                /* input buffer */
  7.     register char
  8.         *cp;
  9.         
  10.     while (1)
  11.     {
  12.         fgets (buf, 999, inf);            /* try to read line */
  13.         
  14.         if (feof (inf))                /* return failure when */
  15.            return (NULL);            /* at EOF */
  16.            
  17.         if (buf [0] == '#')            /* ignore lines starting */
  18.             continue;                /* with hashmark */
  19.            
  20.         cp = buf + strlen (buf) - 1;        /* strip whitespace at end */
  21.         while (isspace (*cp) && cp > buf)
  22.         {
  23.             *cp = '\0';
  24.             cp--;
  25.         }
  26.         
  27.         if (cp == buf)                /* ignore empty lines */
  28.             continue;
  29.         
  30.         cp = buf;                /* skip leading spaces */
  31.         while (isspace (*cp))
  32.             cp++;
  33.             
  34.         return (cp);                /* return that position */
  35.     }
  36. }
  37.